package com.ms.dsq_english.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateUtils
{
    public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_FORMAT_DATE = "yyyyMMdd";
    public static final String DATE_FORMAT_DATE_ = "yyyy-MM-dd";
    public static final String DATE_FORMAT_DATE_CN = "yyyy年MM月dd日";
    public static final String DATE_FORMAT_YEAR = "yyyy";
    public static final String DATE_FORMAT_MONTH = "MM";
    public static final String DATE_FORMAT_MONTH_ = "yyyy-MM";
    public static final String DATE_FORMAT_MONTH__ = "yyyy.MM";
    public static final String DATE_FORMAT_MONTH_CN = "yyyy年MM月";
    public static final String DATE_FORMAT_DAY = "dd";
    public static final String DATE_FORMAT_HOUR_WEEK = "HH:mm:ss EEEE";

    public static String getDate(String type)
    {
        return new SimpleDateFormat(type, Locale.getDefault()).format(new Date());
    }

    public static String getDateEn(String type)
    {
        return new SimpleDateFormat(type, Locale.ENGLISH).format(new Date());
    }

    public static String getMonth_EN()
    {
        return new SimpleDateFormat("MMM", Locale.ENGLISH).format(new Date());
    }

    public static String getDateCalculate(int calculateType, int value, String formatType)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(calculateType, value);

        return new SimpleDateFormat(formatType, Locale.getDefault()).format(calendar.getTime());
    }

    public static long getDateCalculateByTime(long currentTime, int calculateType, int value)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(currentTime));
        calendar.add(calculateType, value);

        return calendar.getTime().getTime();
    }

    public static String getWeek()
    {
        switch (Calendar.getInstance().get(Calendar.DAY_OF_WEEK))
        {
            case 1:
                return "星期日";
            case 2:
                return "星期一";
            case 3:
                return "星期二";
            case 4:
                return "星期三";
            case 5:
                return "星期四";
            case 6:
                return "星期五";
            case 7:
                return "星期六";
        }

        return "";
    }

    //Long->String
    public static String formatDate(String type, long timeLong)
    {
        return new SimpleDateFormat(type, Locale.getDefault()).format(new Date(timeLong));
    }

    //String->Long
    public static Long parseDate(String type, String timeString)
    {
        Long time = null;
        try
        {
            time = new SimpleDateFormat(type, Locale.getDefault()).parse(timeString).getTime();
        }
        catch (ParseException e) {e.printStackTrace();}

        return time;
    }


}
